package com.service.admin.impl;

import com.dao.OrderDao;
import com.entity.Order;
import com.service.admin.AdminOrderService;
import com.utils.SqlSessionGetter;

import org.apache.ibatis.session.SqlSession;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 管理员关于订单服务的实现类
 *
 * 
 */
@Service
public class AdminOrderServiceImpl implements AdminOrderService {

  @Override
  public int getAllOrderCount(int orderStatus) {
    SqlSession session = SqlSessionGetter.getSqlSession();
    OrderDao dao = session.getMapper(OrderDao.class);
    int count = dao.selectAllOrderCount(orderStatus);
    session.close();
    return count;
  }

  @Override
  public List<Order> getAllOrders(int orderStatus, int pageSize, int pageIndex) {
    SqlSession session = SqlSessionGetter.getSqlSession();
    OrderDao dao = session.getMapper(OrderDao.class);
    List<Order> orders = dao.selectAllOrders(orderStatus, pageIndex * pageSize, pageSize);
    session.close();
    return orders;
  }
}
